<%@ include file="/WEB-INF/views/commonJSTL.jsp" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>${s_UserPharmacy.pharmacy.name}</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<%@ include file="/WEB-INF/views/commonResources.jsp" %>

<script type="text/javascript">
$(document).ready(function(){
});


	function newUser(){
    	location.href = "adminUserNew?_menuId=2&_subMenuId=3";
	}
	
	function edit(pharmacyId,userId){
    	location.href = "adminUserEdit?_menuId=2&_subMenuId=3&_userId="+userId+"&_pharmacyId="+pharmacyId;
	}
	
	function giveLow(pharmacyId,userId,name){
	    if(confirm("¿Estas seguro de dar de baja al Usuario: "+name+"?")){
            $.ajax({
                url: "ajaxGiveLowOrHighToUser",
                type: "GET",
                data:{pharmacyId:pharmacyId,userId:userId,active:false},
                beforeSend:function(obj){
                    $('#listUser').css({display:'none'});
                    $('#imgLoad').css({display:'block'});
                },
                success:function(res){
                	alert(res);
                	location.href = "adminHumanResources?_menuId=2&_subMenuId=3";
                },
                complete:function(){
                    $('#imgLoad').css({display:'none'});
                    $("#listUser").css({display:'block'});
                },
                error: function(res){ alert("Error! al dar de Baja"); }
            });
        }
	}
	function giveHigh(pharmacyId,userId,name){
		if(confirm("¿Estas seguro de dar de alta al Usuario: "+name+"?")){
            $.ajax({
                url: "ajaxGiveLowOrHighToUser",
                type: "GET",
                data:{pharmacyId:pharmacyId,userId:userId,active:true},
                beforeSend:function(obj){
                    $('#listUser').css({display:'none'});
                    $('#imgLoad').css({display:'block'});
                },
                success:function(res){
                	alert(res);
                	location.href = "adminHumanResources?_menuId=2&_subMenuId=3";
                },
                complete:function(){
                    $('#imgLoad').css({display:'none'});
                    $("#listUser").css({display:'block'});
                },
                error: function(res){ alert("Error! al dar de Alta"); }
            });
        }
	}
	
	
	
	function showHide(){
	    if( $("#userLow").css('display') == 'none' ){
	        $("#userLow").css('display', 'block');
	        $("#showHide").attr('value', 'Ocultar Bajas');
	        $("#showHide").attr('title', 'Pulsa aqui para ocultar bajas')
	    }else{
	        $("#userLow").css('display', 'none');
	        $("#showHide").attr('value', 'Mostrar Bajas');
	        $("#showHide").attr('title', 'Pulsa aqui para mostrar bajas')
	    }
	}

</script>
</head>

<body>
<div id="top-wrap">
	<%@include file="../../head.jsp"  %>
	<div id="bodySpace">
		
	    <div class="clearfix" id="middle" style="position: absolute">  <!-- aqui va la ruta -->
	        <!-- aqui va el arbol de entrada -->
	        <div id="breadcrumb">
	            <ul>
                	<li><a href="<spring:url value="/mainFront?" htmlEscape="true" />">Home</a></li>	
                    <li><span style="color:#666"><fmt:message key="title.admin"/></span></li>
                    <li><span style="color:#666"><fmt:message key="title.resourceHuman"/></span></li>
                    <li class="current-page"><span class="end"><span class="middle"><fmt:message key="title.users"/></span></span></li>
                </ul>
	        </div>
	    </div>
	    
	    <div id="principal">
            <!-- izquierda -->
            <div class="cuerpo2y" style="border: 0px solid"><br/><br/><!-- estos break son necesarios ya q uso absolute en css  cuerpo izquierdo-->
                <div class="izq">
					<%@include file="../../bodyIzq.jsp" %>	
                </div>
                
                <div class="medio" style="border: 0px solid">
					<h2 class="decorado"><fmt:message key="title.users"/></h2></br></br> 
					<h3 class="decorado"><fmt:message key="title.list.users"/></h3>
					
					<div id="imgLoad" style="float: left;width: 100%;display: none;"><img src="<c:url value="/resources/images/imgLoad/ajax-loader.gif" />" width="32" height="32" alt="ajax-loader.gif" style="position:absolute; top:30%; left:50%;"/></div> 
					<div id="listUser">
						<table class="miReporte" style="width: 100%">
							<tr>
								<td style="text-align: right"><input type="button" class="boton" value="<fmt:message key="button.add"/> <fmt:message key="title.user"/>" onclick="newUser()" title='<fmt:message key="onclick.add"/> <fmt:message key="title.user"/>'/></td>
							</tr>
						</table>
						<table class="tabla_decorado" style="width: 100%">
							<thead>
								<tr>
									<th width="3%" class="th_decoradoRowspan"><fmt:message key="table.num"/></th>	
									<!-- th width="19%" class="th_decoradoRowspan"><fmt:message key="table.id"/></th-->
									<th width="10%" class="th_decoradoRowspan"><fmt:message key="table.login"/></th>
									<th width="15%" class="th_decoradoRowspan"><fmt:message key="table.name"/></th>
									<th width="30%" class="th_decoradoRowspan"><fmt:message key="table.lastName"/></th>
									<th width="8%" class="th_decoradoRowspan"><fmt:message key="table.ci"/></th>
									<th width="15%" class="th_decoradoRowspan"><fmt:message key="table.pharmasoft"/></th>
									<th width="16%" class="th_decoradoRowspan" colspan="2"><fmt:message key="table.actions"/></th>
								</tr>
							</thead>
							<tbody>
								<c:set var="i" value="1"/>
								<c:forEach items="${userPharmacyActive}" var="userPhar">                                	
									<tr class="tr_decorado">
										<td class="th_decorado" style="text-align: center">${i}</td>
										<!-- td class="th_decorado">${userPhar.userpharmacyPK.userId}</td-->
										<td class="th_decorado">${userPhar.user.login}</td>
										<td class="th_decorado">${userPhar.user.name}</td>
										<td class="th_decorado">${userPhar.user.lastName} ${userPhar.user.lastName2}</td>
										<td class="th_decorado">${userPhar.user.ci}</td>
										<td class="th_decorado">${userPhar.pharmacy.name}</td>
										<td class="td_decoradoDerecha" style="text-align: center"><input type="button" value="<fmt:message key="button.edit"/>" onclick="edit(${userPhar.userpharmacyPK.pharmacyId},${userPhar.userpharmacyPK.userId})" class="botonRep" title="<fmt:message key="onclick.edit"/> ${userPhar.user.name}"/></td>
										<td class="td_decoradoDerecha" style="text-align: center"><input type="button" value="<fmt:message key="button.low"/>" onclick="giveLow(${userPhar.userpharmacyPK.pharmacyId},${userPhar.userpharmacyPK.userId},'${userPhar.user.name}')" class="botonRep" title="<fmt:message key="onclick.low"/> ${userPhar.user.name}"/></td>
									</tr>
									<c:set var="j" value="1"/>
	                            	<c:set var="i" value="${i+j}"/>
								</c:forEach>
							</tbody>
						</table>
						<!-- boton que muestra y oculta los Administrativos dados de baja -->                
						<table class="miReporte" style="width: 100%">
							<tr>
								<td style="text-align: right"><input type="button" name="showHide" id="showHide" value="<fmt:message key="show.low"/>" onclick="showHide()" class="boton" title="<fmt:message key="onclick.show.lows"/>"/></td>
							</tr>
						</table><br/><br/>
					</div>	                                
					<c:choose>
						<c:when test="${(not empty userPharmacyInActive)}" >
							<div id="userLow" style="display:none;">
								<!-- <center> -->
								<h2 class="decorado"><fmt:message key="show.usersGiveLow"/></h2>
								<table class="tabla_decorado" style="width: 100%">
									<thead>
										<tr>
											<th width="3%" class="th_decoradoRowspan"><fmt:message key="table.num"/></th>
											<th width="19%" class="th_decoradoRowspan"><fmt:message key="table.id"/></th>
											<th width="14%" class="th_decoradoRowspan"><fmt:message key="table.name"/></th>
											<th width="9%" class="th_decoradoRowspan"><fmt:message key="table.lastName"/></th>
											<th width="8%" class="th_decoradoRowspan"><fmt:message key="table.ci"/></th>
											<th width="15%" class="th_decoradoRowspan"><fmt:message key="table.pharmasoft"/></th>
											<th width="16%" class="th_decoradoRowspan" colspan="1"><fmt:message key="table.actions"/></th>
										</tr>
									</thead>
									<tbody>
										<c:set var="i" value="1"/>
										<c:forEach items="${userPharmacyInActive}" var="userPhar">
											<tr class="tr_decorado">
												<td class="th_decorado" style="text-align: center">${i}</td>
												<td class="th_decorado">${userPhar.userpharmacyPK.userId}</td>
												<td class="th_decorado">${userPhar.user.name}</td>
												<td class="th_decorado">${userPhar.user.lastName}</td>
												<td class="th_decorado">${userPhar.user.ci}</td>    
												<td class="th_decorado">${userPhar.pharmacy.name}</td>
												<td class="td_decoradoDerecha" style="text-align: center"><input type="button" value="<fmt:message key="button.high"/>" onClick="giveHigh(${userPhar.userpharmacyPK.pharmacyId},${userPhar.userpharmacyPK.userId},'${userPhar.user.name}')" class="botonRep" title="<fmt:message key="onclick.high"/> ${userPhar.user.name}"/></td>
											</tr>
											<c:set var="j" value="1"/>
	                            			<c:set var="i" value="${i+j}"/>
										</c:forEach>                              		
									</tbody>
								</table>
							</div>									
						</c:when>
						<c:otherwise>
							<p style='text-align:center;color:blue'>
								<fmt:message key="show.noExistUsersGiveLow"/>
							</p>
						</c:otherwise>
					</c:choose>
                </div>
            </div><!--end of leftPan-->
            
            <div class="yDer" style="border: 1px solid #ccc;">
                  <%@include file="../../notices.jsp" %>                       
            </div><!--end of rightPan-->
        </div><!--end main content -->
	</div>
</div>
</body>
</html>
